package com.xxxx.comment.config;

import com.xxxx.comment.service.FileStorageService;
import io.minio.MinioClient;
import jakarta.annotation.Resource;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Data
@Configuration
@EnableConfigurationProperties({MinIOConfigProperties.class})
// 只有项目中存在FileStorageService接口时MinIOConfig类才可以被编译加载
@ConditionalOnClass(FileStorageService.class)
public class MinIOConfig
{
    @Resource
    private MinIOConfigProperties minIOConfigProperties;

    @Bean
    public MinioClient buildMinioClient()
    {
        return MinioClient
                .builder()
                .credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey())
                .endpoint(minIOConfigProperties.getEndpoint())
                .build();
    }
}
